#!/usr/bin/env python3
# -*- coding: utf-8 -*-

"""
终端查询使用示例

@author liaochangyi
@since 2025-01-25
"""

import os
import sys

# 添加项目根目录到Python路径，确保能够导入jlpay包
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))))

from examples.base_example import BaseExample
from jlpay.services.openmerch.device.device_service import DeviceService
from jlpay.model.openmerch.device.device import DeviceQueryRequest


class DeviceQueryExample(BaseExample):
    """终端查询示例类"""

    def __init__(self):
        """初始化示例类"""
        super().__init__("examples.openmerch.device.query")
        self.device_service = DeviceService(self.config)

    def build_device_query_request(self):
        """构建终端查询请求"""
        request = DeviceQueryRequest()

        # 设置请求参数
        request.set_merch_no("84944035812S123")
        # 可选参数，注释掉表示查询该商户下所有终端
        # request.set_device_no("AQR1000030")
        # request.set_term_no("AQR1000030")

        return request

    def demo(self):
        """执行终端查询示例"""
        self.logger.info("开始执行终端查询示例")

        # 创建终端查询请求
        request = self.build_device_query_request()

        # 发送请求
        response = self.send_request_and_handle_response(
            self.device_service.device_query,
            "终端查询",
            request
        )

        # 处理响应结果
        if response and response.is_success():
            self.logger.info(f"响应报文：{response.to_dict()}")

        self.logger.info("终端查询示例执行完毕")


if __name__ == "__main__":
    example = DeviceQueryExample()
    example.demo() 